package strategy

// Constraint 支持多个约束项，按数组顺序表示优先级
type Constraint struct {
	Constraints []ConstraintType
}

var constraintMap = map[ConstraintType]func() Strategy{
	MinHop:            func() Strategy { return &MinHopStrategy{} },
	MinDelay:          func() Strategy { return &MinDelayStrategy{} },
	BalancedBandwidth: func() Strategy { return &BalancedBandwidthStrategy{} },
	MinCost:           func() Strategy { return &MinCostStrategy{} },
	MustPass: func() Strategy {
		return &MustPassStrategy{}
	},
}

func CreateStrategy(constraint Constraint, mustPassCfg *MustPassConfig, notPassCfg *MustNotPassConfig) *CompositeStrategy {
	strategies := make([]Strategy, 0, len(constraint.Constraints))
	// for _, ct := range constraint.Constraints {
	// 	if factory, exists := constraintMap[ct]; exists {
	// 		strategies = append(strategies, factory())
	// 	}
	// }
	for _, ct := range constraint.Constraints {
		switch ct {
		case MinHop:
			strategies = append(strategies, &MinHopStrategy{})
		case MinDelay:
			strategies = append(strategies, &MinDelayStrategy{})
		case BalancedBandwidth:
			strategies = append(strategies, &BalancedBandwidthStrategy{})
		case MinCost:
			strategies = append(strategies, &MinCostStrategy{})
		case MustPass:
			if mustPassCfg != nil && len(mustPassCfg.Nodes) > 0 {
				strategies = append(strategies, &MustPassStrategy{requiredNodes: mustPassCfg.Nodes})
			}
		case MustNotPass:
			if notPassCfg != nil && len(notPassCfg.Nodes) > 0 {
				strategies = append(strategies, &MustNotPassStrategy{forbiddenNodes: notPassCfg.Nodes})
			}
		}
	}
	return NewCompositeStrategy(strategies)
}
